define(['jquery','utils','uikit'],function ($,utils,uikit) {
	function Info() {
		this.CourseId = utils.InfoCourseId();
	}

	Info.prototype = {
		init () {
			utils.setBannerHeight();
			this.BuyCart()
			this.BuyAdd()
		},

		/**
		 * 收费视频购买按钮被点击
		 * @constructor
		 */
		BuyCart () {
			$('.buyCart').on('click', () => {
				if (localStorage.getItem("objectId") == null) {
					uikit.notification({
						message: '请先登录',
						status: 'danger',
						pos: 'top-right',
						timeout: 5000
					});
					location.href = `/reg?from=${location.pathname}`
				} else {
					utils.post({
						url: '/car/addCourseToCart',
						data: {
							courseid: this.CourseId,
							userid: utils.getUserId()
						}
					}, res => {
						if(!(res['result'].hasOwnProperty("orderStatus"))) {
							uikit.notification({
								message: '添加购物车成功',
								status: 'success',
								pos: 'top-right',
								timeout: 5000
							});
							location.href = `/car`
						} else {
							uikit.notification({
								message: '不要重复添加',
								status: 'danger',
								pos: 'top-right',
								timeout: 5000
							});
						}
					})
				}

			})
		},

		/**
		 * 课程收藏按钮被点击
		 * @constructor
		 */
		BuyAdd () {
			$('.buyAdd').on('click', () => {
				alert(this.CourseId)
			})
		}
	};

	return new Info();
});